{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ec2224c4-9f14-4ebe-b0a0-fb05ba043d68",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\hpcq_\\.conda\\envs\\cvxpyenv\\lib\\site-packages\\arctic-1.80.0-py3.8.egg\\arctic\\store\\_pandas_ndarray_store.py:8: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version\n"
     ]
    }
   ],
   "source": [
    "from arctic import TICK_STORE, Arctic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0c15ddbf-c10c-460e-9134-27cc1a60e604",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3087554b-1526-4bf3-8e27-9b576c9e0b9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "lib = Arctic('localhost')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "205ea65a-fd3e-40a7-bdbe-6a5a9edf46ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "# lib.initialize_library('tick', lib_type=TICK_STORE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4eecd808-c8df-4763-950d-3b11c309aea7",
   "metadata": {},
   "outputs": [],
   "source": [
    "tick = lib.get_library('tick')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "33982bc7-888f-485f-b3f2-49cd7d1d20d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv('temp/000001.csv', index_col=0, parse_dates=True).tz_localize('UTC')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0abd0890-eb02-4a29-be49-511c72a5e570",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "NB treating all values as 'exists' - no longer sparse\n"
     ]
    }
   ],
   "source": [
    "tick.write('000001', data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8b74603c-d922-4908-a326-029746ad7d61",
   "metadata": {},
   "outputs": [],
   "source": [
    "fund = lib.get_library('fund')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fce9748f-5f36-48bf-990a-467cae11056e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2021, 4, 22, 1, 0, tzinfo=tzfile('GB-Eire'))"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick.max_date('000001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2242f0e1-394b-4fca-a4f5-0a292040761c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2021, 4, 2, 1, 0, tzinfo=tzfile('GB-Eire'))"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick.min_date('000001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f6bbbe3c-0648-493d-ac02-fdac47cfcd2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAV</th>\n",
       "      <th>ACC_NAV</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-04-02</th>\n",
       "      <td>1.335</td>\n",
       "      <td>3.846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-05</th>\n",
       "      <td>1.335</td>\n",
       "      <td>3.846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-06</th>\n",
       "      <td>1.327</td>\n",
       "      <td>3.838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-07</th>\n",
       "      <td>1.318</td>\n",
       "      <td>3.829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-08</th>\n",
       "      <td>1.334</td>\n",
       "      <td>3.845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-09</th>\n",
       "      <td>1.316</td>\n",
       "      <td>3.827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-12</th>\n",
       "      <td>1.296</td>\n",
       "      <td>3.807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-13</th>\n",
       "      <td>1.301</td>\n",
       "      <td>3.812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-14</th>\n",
       "      <td>1.310</td>\n",
       "      <td>3.821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-15</th>\n",
       "      <td>1.299</td>\n",
       "      <td>3.810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-16</th>\n",
       "      <td>1.299</td>\n",
       "      <td>3.810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-19</th>\n",
       "      <td>1.321</td>\n",
       "      <td>3.832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-20</th>\n",
       "      <td>1.331</td>\n",
       "      <td>3.842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-21</th>\n",
       "      <td>1.346</td>\n",
       "      <td>3.857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-22</th>\n",
       "      <td>1.348</td>\n",
       "      <td>3.859</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              NAV  ACC_NAV\n",
       "date                      \n",
       "2021-04-02  1.335    3.846\n",
       "2021-04-05  1.335    3.846\n",
       "2021-04-06  1.327    3.838\n",
       "2021-04-07  1.318    3.829\n",
       "2021-04-08  1.334    3.845\n",
       "2021-04-09  1.316    3.827\n",
       "2021-04-12  1.296    3.807\n",
       "2021-04-13  1.301    3.812\n",
       "2021-04-14  1.310    3.821\n",
       "2021-04-15  1.299    3.810\n",
       "2021-04-16  1.299    3.810\n",
       "2021-04-19  1.321    3.832\n",
       "2021-04-20  1.331    3.842\n",
       "2021-04-21  1.346    3.857\n",
       "2021-04-22  1.348    3.859"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fund.read('000001', pd.date_range('20210402', '20210422'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "220296b7-84f5-4f36-a459-a888f31802fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from arctic.date import DateRange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "cb1d9d9a-82e6-4769-b43c-bf7f7b8f8c63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAV</th>\n",
       "      <th>ACC_NAV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-04-02 01:00:00+01:00</th>\n",
       "      <td>1.335</td>\n",
       "      <td>3.846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-05 01:00:00+01:00</th>\n",
       "      <td>1.335</td>\n",
       "      <td>3.846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-06 01:00:00+01:00</th>\n",
       "      <td>1.327</td>\n",
       "      <td>3.838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-07 01:00:00+01:00</th>\n",
       "      <td>1.318</td>\n",
       "      <td>3.829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-08 01:00:00+01:00</th>\n",
       "      <td>1.334</td>\n",
       "      <td>3.845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-09 01:00:00+01:00</th>\n",
       "      <td>1.316</td>\n",
       "      <td>3.827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-12 01:00:00+01:00</th>\n",
       "      <td>1.296</td>\n",
       "      <td>3.807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-13 01:00:00+01:00</th>\n",
       "      <td>1.301</td>\n",
       "      <td>3.812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-14 01:00:00+01:00</th>\n",
       "      <td>1.310</td>\n",
       "      <td>3.821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-15 01:00:00+01:00</th>\n",
       "      <td>1.299</td>\n",
       "      <td>3.810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-16 01:00:00+01:00</th>\n",
       "      <td>1.299</td>\n",
       "      <td>3.810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-19 01:00:00+01:00</th>\n",
       "      <td>1.321</td>\n",
       "      <td>3.832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-20 01:00:00+01:00</th>\n",
       "      <td>1.331</td>\n",
       "      <td>3.842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-21 01:00:00+01:00</th>\n",
       "      <td>1.346</td>\n",
       "      <td>3.857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             NAV  ACC_NAV\n",
       "2021-04-02 01:00:00+01:00  1.335    3.846\n",
       "2021-04-05 01:00:00+01:00  1.335    3.846\n",
       "2021-04-06 01:00:00+01:00  1.327    3.838\n",
       "2021-04-07 01:00:00+01:00  1.318    3.829\n",
       "2021-04-08 01:00:00+01:00  1.334    3.845\n",
       "2021-04-09 01:00:00+01:00  1.316    3.827\n",
       "2021-04-12 01:00:00+01:00  1.296    3.807\n",
       "2021-04-13 01:00:00+01:00  1.301    3.812\n",
       "2021-04-14 01:00:00+01:00  1.310    3.821\n",
       "2021-04-15 01:00:00+01:00  1.299    3.810\n",
       "2021-04-16 01:00:00+01:00  1.299    3.810\n",
       "2021-04-19 01:00:00+01:00  1.321    3.832\n",
       "2021-04-20 01:00:00+01:00  1.331    3.842\n",
       "2021-04-21 01:00:00+01:00  1.346    3.857"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick.read('000001', DateRange('20210402', '20210422'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "951fa034-214d-4cec-a694-6ba0129260a5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2574732-9a59-4bcc-8e9f-2133a025e9ac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41004e65-3c88-4861-ad6b-c35049e51731",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "73d28bf3-0027-4e26-bf89-d2e859c5b017",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tzlocal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "5ffd62e0-8623-4db4-a9d4-89ef92f075cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "z = tzlocal.get_localzone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "976e3c7d-00b7-4c66-97cb-3ebcd5c1513b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import dateutil\n",
    "import six\n",
    "import tzlocal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "6ca1916a-7cfa-49da-b5fe-e9931e04a2f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "zone=None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "9c785a32-3bf0-4be5-b9d8-18792dff9f54",
   "metadata": {},
   "outputs": [],
   "source": [
    "if zone is None:\n",
    "    zone = tzlocal.get_localzone().key\n",
    "zone = six.u(zone)\n",
    "tz = dateutil.tz.gettz(zone)\n",
    "if not tz:\n",
    "    raise TimezoneError('Timezone \"%s\" can not be read' % (zone))\n",
    "# Stash the zone name as an attribute (as pytz does)\n",
    "if not hasattr(tz, 'zone'):\n",
    "    tz.zone = zone\n",
    "    for p in dateutil.tz.TZPATHS:\n",
    "        if zone.startswith(p):\n",
    "            tz.zone = zone[len(p) + 1:]\n",
    "            break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "c5087f33-bad4-408b-8a14-72345eaebfd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Europe/London'"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4443e3c2-246d-4ac1-8b01-1acceefbedf2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
